﻿using Enter.Admin.Dtoes;
using FluentValidation;

namespace Enter.Admin.Configs.Validator
{
    public class EmployModelValidator : AbstractValidator<EmployModel>
	{		
		public EmployModelValidator()
		{
			// https://docs.fluentvalidation.net/en/latest/rulesets.html
			// https://docs.fluentvalidation.net/en/latest/aspnet.html#validator-customization
			// RuleSet("Names", () => {				
			// });

			
			RuleSet("Create", () => {
				RuleFor(x => x.UserName).NotNull().WithMessage("用户名不能为空").MinimumLength(2).WithMessage("用户名最少2个长度");
				RuleFor(x => x.Password).NotNull().WithMessage("密码不能为空").MinimumLength(6).WithMessage("密码最少66个长度");
			});
			RuleFor(x => x.Password).MinimumLength(6).When(t => !string.IsNullOrWhiteSpace(t.Password)).WithMessage("密码最少77个长度");
		}
	}
}
